/*
 * Copyright (C) 2010 Zaizi Limited.
 *
 * This file is part of Zaizi Framework
 *
 * Zaizi REST Client is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Zaizi REST Client is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Zaizi REST Client. If not, see <http://www.gnu.org/licenses/>.
 */
package org.zaizi.restclient;

/**
 * Implement a service endpoint
 * 
 * @author efoncubierta
 * 
 */
public class Endpoint
{
	
	// Default values
	public static final String DEFAULT_PROTOCOL = "http";
	public static final String DEFAULT_HOST = "localhost";
	public static final String DEFAULT_PORT = "80";
	
	// Constants
	public static final String PROTOCOL_HTTP  = "http";
	public static final String PROTOCOL_HTTPS = "https";
	
	// Properties
	private String protocol;
	private String host;
	private String port;
	private String uri;
	
	/**
	 * Get the endpoint protocol (http, https...)
	 * 
	 * @return Protocol
	 */
	public String getProtocol()
	{
		return protocol;
	}
	
	/**
	 * Set the endpoint protocol (http, https...)
	 * 
	 * @param protocol Protocol
	 */
	public void setProtocol(String protocol)
	{
		this.protocol = protocol;
	}
	
	/**
	 * Get the endpoint host
	 * 
	 * @return Host
	 */
	public String getHost()
	{
		return host;
	}
	
	/**
	 * Set the endpoint host
	 * 
	 * @param host Host
	 */
	public void setHost(String host)
	{
		this.host = host;
	}
	
	/**
	 * Get the endpoint port
	 * 
	 * @return Port
	 */
	public String getPort()
	{
		return port;
	}
	
	/**
	 * Set the endpoint port
	 * 
	 * @param port Port
	 */
	public void setPort(String port)
	{
		this.port = port;
	}
	
	/**
	 * Get the enpoint base URI
	 * 
	 * @return Base URI
	 */
	public String getUri()
	{
		return uri;
	}
	
	/**
	 * Set the endpoint base URI
	 * 
	 * @param uri Base URI
	 */
	public void setUri(String uri)
	{
		this.uri = uri;
	}
	
	/**
	 * Represent the endpoint as a String
	 * 
	 * @return Endpoint as a String
	 */
	public String toString()
	{
		StringBuilder sb = new StringBuilder();
		sb.append(protocol == null ? DEFAULT_PROTOCOL : protocol);
		sb.append("://");
		sb.append(host == null ? DEFAULT_HOST : host);
		sb.append(":");
		sb.append(port == null ? DEFAULT_PORT : port);
		sb.append(uri == null ? "" : uri);
		return sb.toString();
	}
}
